#ifndef FCAP_CTRL_H
#define FCAP_CTRL_H

//#define million_pixel

#define WORD_SIZE 0x10


#if 0 
struct fcap_device 
{
	struct video_device vdev;
	///struct semaphore lock;
	int width, height;

};
#endif


// --------------------------------------------------------------------
//		control register
// --------------------------------------------------------------------
	#define CAP_FPS_30			(0x0<<12)			// capture frame rate
	#define CAP_FPS_15			(0x1<<12)
	#define CAP_FPS_10			(0x2<<12)
	#define CAP_FPS_6			(0x4<<12)
	#define CAP_FPS_5			(0x5<<12)
	#define CAP_FPS_3			(0x9<<12)
	#define CAP_FPS_2			(0xe<<12)	

	#define CTRL_YSEQ_ALL		(0x3<<8)		// Output data format even and odd field enable
	#define CTRL_YSEQ_ODD		(0x2<<8)		// Output data format odd field enable	
	#define CTRL_YSEQ_EVEN		(0x1<<8)		// Output data format even field enable		
	#define CTRL_VSINT			(0x1<<7)			// V-sync interrupt enable
	#define CTRL_SEINT			(0x1<<6)			// sync error interrupt enable
	#define CTRL_TEINT			(0x1<<5)			// transfer error interrupt enable
	#define CTRL_FTINT			(0x1<<4)			// frame transfer done interrupt enable
	#define CTRL_INTACK			(0x1<<3)			// interrupt acknowledge
	#define CTRL_PENB			(0x1<<2)			// pause function enable
	#define CTRL_CENB			(0x1<<1)			// capture enable
	#define CTRL_RST			(0x1<<0)			// reset

// --------------------------------------------------------------------
//		format register
// --------------------------------------------------------------------
	#define DATAFMT_2D			(0x1<<8)
	#define CTRL_YUVIFMT			(0x1<<10)			// YUV input data format		
	// --------------------------------------------------------------------
	//		input video format
	// --------------------------------------------------------------------
	#define IN_FMT_CCIR601_NTSC	(0x0<<4)
	#define IN_FMT_CCIR601_PAL	(0x1<<4)
	#define IN_FMT_CCIR656_NTSC	(0x2<<4)

	#define IN_FMT_CCIR656_PAL	(0x3<<4)
	#define IN_FMT_CCIR601_VGA	(0x4<<4)
	#define IN_FMT_CCIR656_VGA	(0x6<<4)
	#define IN_FMT_MASK			(0x7<<4)
	
	// --------------------------------------------------------------------
	//		output video format
	// --------------------------------------------------------------------
	#define OUT_SOFMT			0x800	
	#define OUT_FMT_422			(0x0<<2)
	#define OUT_FMT_420			(0x1<<2)
	#define OUT_FMT_MASK		(0x3<<2)
	
	// --------------------------------------------------------------------
	// 		output frame size
	// --------------------------------------------------------------------

	#define OUT_SIZE_FULL		(0x0)
	#define OUT_SIZE_CIF		(0x1)
	#define OUT_SIZE_QCIF		(0x2)
	#define OUT_SIZE_MASK		(0x3)
	

typedef struct
{
  	ulong Control;
  	ulong Format;
  	ulong Status;
  	ulong Reserved0;
  	ulong Ybase;
  	ulong High;
  	ulong Times;
  	ulong Reserved3;      
  	ulong Ubase;
  	ulong Reserved4;
  	ulong Reserved5;
  	ulong Reserved6;      
  	ulong Vbase;
  	ulong Reserved7;
  	ulong Reserved8;
  	ulong Reserved9;      
	ulong Ystride;		// 0x40
	ulong Ustride;
	ulong Vstride;
	ulong Reserved10;
	ulong Framecnt;	// 0x50
	ulong Reserved11;
  	ulong Reserved12;
  	ulong Reserved13;
	ulong Framedec;	// 0x60
	ulong Reserved14;
  	ulong Reserved15;
  	ulong Reserved16;  	
} CAP;

//
// 	add fro FIE8150 platform
//
#define fcnt 0x1
#define fthreoshold 0x1
#define CAP_CONTROL_OFFSET		0x00
#define CAP_FORMAT_OFFSET		0x04
#define CAP_STATUS_OFFSET		0x08
#define CAP_YBASE_OFFSET		0x10
#define CAP_HIGH_OFFSET			0x14
#define CAP_TIMES_OFFSET		0x18
#define CAP_UBASE_OFFSET		0x20
#define CAP_VBASE_OFFSET		0x30
#define CAP_YSTRIDE_OFFSET		0x40		
#define CAP_USTRIDE_OFFSET		0x44
#define CAP_VSTRIDE_OFFSET		0x48
#define CAP_FRAMECNT_OFFSET	0x50
#define CAP_FRAMEDEC_OFFSET	0x60

extern int RunProgram(char *sa_tokens[]);
extern int fcap_misc_run_7113_userdef(void);

//#define VIDEO_MODE_422
#ifdef million_pixel
#define MAX_WIDTH				1280			///steven SXGA
#else
#define MAX_WIDTH				720			/// 640
#endif
//   #define MAX_HEIGHT				480			/// 480
#ifdef million_pixel
#define MAX_HEIGHT				1024			///steven SXGA
#else
#define MAX_HEIGHT				576			/// 576
#endif

#ifdef VIDEO_MODE_422
   #define BYTES			2
   #define FCAP_MAX_FRAME_SIZE		(MAX_WIDTH*MAX_HEIGHT*BYTES)	/// #define FCAP_MAX_FRAME_SIZE		(352*240*2)
#else
   #define BYTES			3/2
   #define FCAP_MAX_FRAME_SIZE		(MAX_WIDTH*MAX_HEIGHT*BYTES)	/// #define FCAP_MAX_FRAME_SIZE		(352*240*3/2)
#endif

void GPIO_Video_In_Select(int mode);
int FC_set_frame_size(int, __u32 width, __u32 height);
void FC_reset(void);
void FC_reset_hw(void);
void FC_set_seq(__u32 seq);
void FC_trigger_interupt(ulong y, ulong u, ulong v);
void FC_check_intSt(void);
int FC_test_capture(ulong y, ulong u, ulong v);
extern int RunProgram(char *sa_tokens[]);
extern int fcap_misc_run_7113_userdef(void);
extern int fcap_setComs(__u32 width,int);


#endif // FCAP_8120_H




